import { CommonResult, HistoryStatsItem, QueryHistoryTask, StatsItem, TaskItem } from "@/types"
import { http } from "../utils/http"
import { getTaskApiPrefix } from "../utils/config"

// 获取任务API前缀
const TASK_PREFIX = getTaskApiPrefix();

export const listTaskAPI = () => {
	return http<TaskItem[]>({
		url: `${TASK_PREFIX}/tasks/listTask`,
		method: 'GET',
	})
}


export const deleteTaskAPI = (taskId : number) => {
	return http<TaskItem[]>({
		url: `${TASK_PREFIX}/tasks/deleteTask`,
		method: 'DELETE',
		data: {
			id: taskId
		}
	})
}

export const completeTaskAPI = (taskId : number) => {
	return http<CommonResult>({
		url: `${TASK_PREFIX}/tasks/handleCompleteTask`,
		method: 'POST',
		data: {
			id: taskId
		}
	})
}

export const addTaskAPI = (data : TaskItem) => {
	return http<TaskItem[]>({
		url: `${TASK_PREFIX}/tasks/addTask`,
		method: 'POST',
		data
	})
}

export const updateTaskAPI = (data : TaskItem) => {
	return http<TaskItem[]>({
		url: `${TASK_PREFIX}/tasks/updateTask`,
		method: 'POST',
		data
	})
}










export const listHistoryTaskAPI = (data : QueryHistoryTask) => {
	return http<TaskItem[]>({
		url: `${TASK_PREFIX}/taskHistory/listHistoryTask`,
		method: 'GET',
		data
	})
}


export const listHistoryStatsAPI = () => {
	return http<HistoryStatsItem>({
		url: `${TASK_PREFIX}/taskHistory/listHistoryStats`,
		method: 'GET',
	})
}

export const listStatsAPI = () => {
	return http<StatsItem[]>({
		url: `${TASK_PREFIX}/taskStatistics/listStatistics`,
		method: 'GET'
	})
}